import requests
# 调用js文件函数依赖
import execjs

# 编译JS文件
with open('获取cookie-v.js', 'r', encoding='utf-8') as f:
    js_content = f.read()
ctx = execjs.compile(js_content)
# 调用JS函数
result = ctx.call('getV')
print(result)  # 输出: Hello, World!


cookies = {
    'other_uid': 'Ths_iwencai_Xuangu_76wlygyd6ydl4ilkryyv67lkdotnrhp0',
    'ta_random_userid': 'x37x4lbtm2',
    'cid': '6fe1aea4ac5554306bb91200d5ac07771731828638',
    ## v 是反爬
    # 'v': 'A421bkld1lUjEXJ5pBc6yvgmnKICasCjS58lBs8RylOSv6Pcl7rRDNvuNfxc',
    'v':result
}

headers = {
    'Referer': 'https://www.iwencai.com/unifiedwap/result?w=5G&querytype=stock&addSign=1731828693321',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0',
    # 'hexin-v': 'A421bkld1lUjEXJ5pBc6yvgmnKICasCjS58lBs8RylOSv6Pcl7rRDNvuNfxc',
}

json_data = {
    'source': 'Ths_iwencai_Xuangu',
    'version': '2.0',
    'query_area': '',
    'block_list': '',
    'add_info': '{"urp":{"scene":1,"company":1,"business":1},"contentType":"json","searchInfo":true}',
    'question': '5G',
    'perpage': 50,
    'page': 1,
    'secondary_intent': 'stock',
    'log_info': '{"input_type":"typewrite"}',
    'rsh': 'Ths_iwencai_Xuangu_76wlygyd6ydl4ilkryyv67lkdotnrhp0',
}

response = requests.post(
    'https://www.iwencai.com/customized/chart/get-robot-data',
    cookies=cookies,
    headers=headers,
    json=json_data,
)

print(response.text)
